package com.hardydou.system.service.impl;

import com.hardydou.system.mapper.SystemResMapper;
import com.hardydou.system.mapper.SystemRoleMapper;
import com.hardydou.system.model.SystemRes;
import com.hardydou.system.model.SystemRole;
import com.hardydou.system.service.ISystemResService;
import com.hardydou.system.service.ISystemRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author ：hardy
 * @description：
 * @date ：Created in 2020-03-10
 * @Copyright ：Hardydou.com
 */
@Service
public class SystemResServiceImpl implements ISystemResService {

    @Autowired
    private SystemResMapper resMapper;

    @Override
    public SystemRes findById(Long resId) {

        return resMapper.selectByPrimaryKey(resId);
    }

    @Override
    public List<SystemRes> findAll(Map params) {
        return resMapper.findAll(params);
    }

    @Override
    public int addRes(SystemRes res) {
        Date date = new Date();
        res.setUtime(date);
        res.setCtime(date);
        return resMapper.insert(res);
    }

    @Override
    public int update(SystemRes res) {
        res.setUtime(new Date());
        return resMapper.updateByPrimaryKeySelective(res);
    }

    @Override
    public int deleteByResId(Long resId) {
        return resMapper.deleteByPrimaryKey(resId);
    }

    @Override
    public List<SystemRes> findByUserId(Long userId) {
        return resMapper.findResByUserId(userId);
    }


    @Override
    public List<SystemRes> findByRoleId(Long roleId) {
        return resMapper.findResByRoleId(roleId);
    }

    @Override
    public List<Map> findAllByRoleId(Long roleId) {
        return resMapper.findAllByRoleId(roleId);
    }

}
